import requests


class Clean_Cache():
    def __init__(self, cacheName, jsonData, clusterName):
        self.params = {
            'clusterName': clusterName,
            'mis': 'yuanyongpo',
        }
        self.url = 'http://hkinfweb.maoyan.team/api/@myredis/category/clean'
        self.headers = {
            'Connection': 'keep-alive',
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36',
            # Already added when you pass json=
            # 'Content-Type': 'application/json',
            'Accept': '*/*',
            'Origin': 'http://hkinfweb.maoyan.team',
            'Referer': 'http://hkinfweb.maoyan.team/myredis/cluster/detail?clusterName=redis-ticketing_prod&activeKey=5',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            # Requests sorts cookies= alphabetically
            # 'Cookie': '_ga=GA1.2.1116089687.1639475294; csrfToken=CazqioxyHKOL-Nes8d51nPjB; JSESSIONID=node0u9u4a9lo4hlsd6jtrc63pbh0303.node0; session=.eJwNzDEOwyAMAMC_MFaNZMDGkM9UxjEdUkGktENU9e9lveG-TlTtPB_vsVt3qwtFBQiieBDPmSiCqcZWOG0pmN085tpai4UlxII5oUeWRLVOoMzu7sZhfWny0tEX3Wd6faRfoz-PsVrcWFGNaf7eNHutFAgBJIEhuN8fhvArFg.FdeWoQ.NZF7eTL-fMLhbiRJ8IElOePUrVw; sso.maoyan.inf.fe.infweb_ssoid=8924f83fffe7f637472dc589d6d8a922*d19a12e602f7ec386c05e3d66b12da1a',
        }
        self.cookies = {
            '_ga': 'GA1.2.1116089687.1639475294',
            'csrfToken': 'CazqioxyHKOL-Nes8d51nPjB',
            'JSESSIONID': 'node0u9u4a9lo4hlsd6jtrc63pbh0303.node0',
            'session': '.eJwNzDEOwyAMAMC_MFaNZMDGkM9UxjEdUkGktENU9e9lveG-TlTtPB_vsVt3qwtFBQiieBDPmSiCqcZWOG0pmN085tpai4UlxII5oUeWRLVOoMzu7sZhfWny0tEX3Wd6faRfoz-PsVrcWFGNaf7eNHutFAgBJIEhuN8fhvArFg.FdeWoQ.NZF7eTL-fMLhbiRJ8IElOePUrVw',
            'sso.maoyan.inf.fe.infweb_ssoid': '8924f83fffe7f637472dc589d6d8a922*d19a12e602f7ec386c05e3d66b12da1a',
        }
        self.cache_name = cacheName
        self.json_data = jsonData

    def clean_redis_category(self):
        for key in self.cache_name:
            self.json_data["name"] = key
            response = requests.post(self.url, params=self.params,
                                     cookies=self.cookies,
                                     headers=self.headers, json=self.json_data, verify=False)
            print(key + response.text)
            self.json_data["name"] = self.cache_name[key]
            response = requests.post(self.url, params=self.params,
                                     cookies=self.cookies,
                                     headers=self.headers, json=self.json_data, verify=False)
            print(self.cache_name[key] + response.text)


if __name__ == '__main__':
    json_data = {
        'cleanMode': 1,
        'cleanTimeType': 1,
        'cleanPattern': 1,
        'read': True,
        'clusterName': 'redis-ticketing_prod',
    }

    ticket_cache_Name = {
        'STOCK_CACHE': '_shadow_STOCK_CACHE',
        'STOCK_RECORD': '_shadow_STOCK_RECORD',
        'SEAT_CHOOSE_QUEUE': '_shadow_SEAT_CHOOSE_QUEUE',
        'STOCK_CACHE_LOCK': '_shadow_STOCK_CACHE_LOCK',
        'STOCK_RECORD_USER_LOCK': '_shadow_STOCK_RECORD_USER_LOCK',
        'STOCK_RECORD_PERFORMANCE': '_shadow_STOCK_RECORD_PERFORMANCE',
        'admission_num': '_shadow_admission_num',
        'admission_queue': '_shadow_admission_queue',
    }

    queue_cache_Name = {
        'GLOBAL_HOT_EVENT_MAP': '',
        'ORDER_PURCHASE_MARK_KEY': '',
    }

    cache_Name = {
        'PUB_EVENT_OUTLET_LIST': '_shadow_PUB_EVENT_OUTLET_LIST',
    }

    ticketCleanCache = Clean_Cache(ticket_cache_Name, json_data, 'redis-ticketing_prod')
    ticketCleanCache.clean_redis_category()

    queueCleanCache = Clean_Cache(queue_cache_Name, json_data, 'redis-virtual_queue_prod')
    queueCleanCache.clean_redis_category()
